/* xerobits.h
**
** Copyright (c) 2006, Damon Orecks <nomadxero@gmail.com>
** All rights reserved.
** 
** Redistribution  and  use  in  source  and  binary  forms,  with  or  without
** modification, are permitted provided that the following conditions are met:
** 
**  * Redistributions of  source code must retain the  above copyright notice,
**    this list of conditions and the following disclaimer.
** 
**  * Redistributions  in  binary  form  must reproduce  the  above  copyright
**    notice,  this list  of conditions  and the  following disclaimer  in the
**    documentation and/or other materials provided with the distribution.
** 
**  * Neither the name  of the Schmoo Group nor the  names of its contributors
**    may be  used to endorse or  promote products derived  from this software
**    without specific prior written permission.
** 
** THIS SOFTWARE IS PROVIDED BY  THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY  EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT  LIMITED TO, THE
** IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR  A PARTICULAR PURPOSE
** ARE DISCLAIMED.  IN NO  EVENT SHALL THE  COPYRIGHT OWNER OR  CONTRIBUTORS BE
** LIABLE  FOR  ANY  DIRECT,   INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
** CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT  LIMITED  TO,  PROCUREMENT  OF
** SUBSTITUTE GOODS  OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
** INTERRUPTION)  HOWEVER CAUSED  AND ON  ANY THEORY  OF LIABILITY,  WHETHER IN
** CONTRACT,  STRICT LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE OR  OTHERWISE)
** ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
**
*/

/**
 ** @file xerobits.h
 **
 ** @brief This file contains data structures and functions for the user-mode
 **        xerobits security library.
 **
 */

/* Macro Definitions */
#ifndef _H_XEROBITS
#define _H_XEROBITS

#ifndef XB_BREAK_ON_NULL
#define XB_BREAK_ON_NULL( var ) if( NULL == var ) { err = XB_ERR_INVALID_PARAM; break; } 
#endif

#define XB_SET_ERROR( fmt, args ) g_set_error( error, quark_xerobits, err, fmt, args );

/* File Includes */
#include "glib.h"

/* Typedefs, Structs, Enums, Unions, etc. */
typedef enum {
  XB_ERR_NOERR = 0,
  XB_ERR_UNKNOWN,
  XB_ERR_UNIMPLEMENTED,
  XB_ERR_INVALID_PARAM,
  XB_ERR_MALLOC,
  XB_ERR_FILE,
  XB_ERR_NOTFOUND
} XB_Err;

typedef struct _XB_Policy {
  guint32 id;
  gchar *name;
  struct _XB_Policy *parent;
  GHashTable *clauses;
} XB_Policy;

typedef enum {
  XB_CTYPE_BOOLEAN = 0,
  XB_CTYPE_INTEGER,
  XB_CTYPE_STRING,
  XB_CTYPE_NET4,
  XB_CTYPE_FILE
} XB_ClauseType;

typedef union {
  gchar *string;
  guint32 integer;
} XB_ClauseValueType;

typedef struct _XB_Clause {
  gchar *id;
  XB_ClauseType ctype;
  XB_ClauseValueType value;
  guint32 flags;
} XB_Clause;

typedef struct {
  gchar *issuer;
  gchar *serial;
  gchar *pem;
  gchar *usage;
} XB_CertificateReference;

typedef struct {
  GPtrArray *certificates;
} XB_Context;

/* Function Prototypes */

/*!
** @brief This function is used to initialize the global xerobits context. In theory, there is
**        but a single such context in an application, and this is the function that initializes
**        it.
**
** @param[in] context
** @param[in] error
**
** @return XB_ERR_NOERR
*/

XB_Err XB_Context_Open( XB_Context *context, GError **error );
XB_Err XB_Context_Close( XB_Context *context );

XB_Err XB_Context_Certificate_Get_Instance_By_Encoding( XB_Context *context, gchar *encoding, GError **error );
XB_Err XB_Context_Certificate_Get_Instance_By_IssuerSerial( XB_Context *context, gchar *issuer, gchar *serial, GError **error );
XB_Err XB_Context_Certificate_Get_Instance_By_Usage( XB_Context, gchar *usage, GError **error );

/* Variable Declarations */
GQuark quark_xerobits;
GQuark quark_openssl;

#endif /* _H_XEROBITS */
